package com.siwei.mes.entity.experiment.concreteAdmixture;

import com.alibaba.fastjson.JSONObject;
import com.siwei.mes.common.util.JsonUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;

/**
 * @Description: 外加剂-凝结时间之差
 * @Version: 1.0
 * @author: YANGKE
 * @date: 2024/07/24 17:29
 */
@Data
@Accessors(chain = true)
public class ConcreteAdmixtureNjsjzc {
    @ApiModelProperty(value = "基准混泥土初凝时间平均值")
    private String jzhntcnsjpjz = "";
    @ApiModelProperty(value = "基准混泥土终凝时间平均值")
    private String jzhntznsjpjz = "";
    @ApiModelProperty(value = "受检混泥土初凝时间平均值")
    private String sjhntcnsjpjz = "";
    @ApiModelProperty(value = "受检混泥土终凝时间平均值")
    private String sjhntznsjpjz = "";
    @ApiModelProperty(value = "初凝时间之差")//1
    private String cnsjzc = "";
    @ApiModelProperty(value = "初凝单项结论")
    private String cndxjl = "";
    @ApiModelProperty(value = "终凝时间之差")//1
    private String znsjzc = "";
    @ApiModelProperty(value = "终凝凝单项结论")
    private String zndxjl = "";
    @ApiModelProperty(value = "凝结时间之差信息")
    private List<ConcreteAdmixtureNjsjzc.NjsjzcList> njsjzcList = Collections.singletonList(new ConcreteAdmixtureNjsjzc.NjsjzcList());


    @Data
    @Accessors(chain = true)
    @ApiModel("凝结时间之差信息")
    public static class NjsjzcList {
        @ApiModelProperty(value = "检测日期")
        private String jcrq = "";
        @ApiModelProperty(value = "基准混凝土加水时间")
        private String jzhntjssj = "";
        @ApiModelProperty(value = "受检混凝土加水时间")
        private String sjhntjssj = "";
        @ApiModelProperty(value = "基准混泥土到达初凝时间")
        private String jzhntddcnsj = "";
        @ApiModelProperty(value = "基准混泥土到达终凝时间")
        private String jzhntddznsj = "";
        @ApiModelProperty(value = "受检混泥土到达初凝时间")
        private String sjhntddcnsj = "";
        @ApiModelProperty(value = "受检混泥土到达终凝时间")
        private String sjhntddznsj = "";
        @ApiModelProperty(value = "混凝土信息")
        private List<HntInfoList> hntInfoList = Collections.singletonList(new HntInfoList());
    }

    @Data
    @Accessors(chain = true)
    @ApiModel("混凝土信息")
    public static class HntInfoList {
        @ApiModelProperty(value = "基准混泥土时间")
        private String jzhntsj = "";
        @ApiModelProperty(value = "基准混泥土贯入阻力")
        private String jzhntgrzl = "";
        @ApiModelProperty(value = "基准混泥土试用面积")
        private String jzhntszmj = "";
        @ApiModelProperty(value = "基准混泥土强度")
        private String jzhntqd = "";
        @ApiModelProperty(value = "受检混泥土时间")
        private String sjhntsj = "";
        @ApiModelProperty(value = "受检混泥土贯入阻力")
        private String sjhntgrzl = "";
        @ApiModelProperty(value = "受检混泥土试用面积")
        private String sjhntszmj = "";
        @ApiModelProperty(value = "受检混泥土强度")
        private String sjhntqd = "";
    }

    /**
     * 字符串转成对象 然后再转成json
     *
     * @param object
     * @return
     */
    private static JSONObject toJsonObject(Object object) {
        ConcreteAdmixtureNjsjzc entity = new ConcreteAdmixtureNjsjzc();
        if (object == null) {
            return JsonUtils.beanToObject(entity);
        }
        if (object instanceof String) {
            entity = JsonUtils.getObject((String) object, ConcreteAdmixtureNjsjzc.class);
        } else if (object instanceof JSONObject) {
            entity = JsonUtils.getObject((JSONObject) object, ConcreteAdmixtureNjsjzc.class);
        }
        return JsonUtils.beanToObject(entity);
    }

    public static String checkIsMust(JSONObject objJson, String name) {
        if (objJson.isEmpty()) {
            return null;
        }
        ConcreteAdmixtureNjsjzc entity = JsonUtils.getObject(objJson, ConcreteAdmixtureNjsjzc.class);
        if (entity == null) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getZnsjzc()) || "null".equals(entity.getZnsjzc())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        if (StringUtils.isBlank(entity.getCnsjzc()) || "null".equals(entity.getCnsjzc())) {
            return "存在必检项(" + name + ")未检测，请先检测！";
        }
        return null;
    }

    public static void setValue(ConcreteAdmixtureNjsjzc entity, Map<String, Object> data) {
        if (data.get("S1Result") != null) {
            entity.setSjhntcnsjpjz(data.get("S1Result").toString());
        }
        if (data.get("V1Result") != null) {
            entity.setSjhntznsjpjz(data.get("V1Result").toString());
        }
        if (data.get("S2Result") != null) {
            entity.setJzhntcnsjpjz(data.get("S2Result").toString());
        }
        if (data.get("V2Result") != null) {
            entity.setJzhntznsjpjz(data.get("V2Result").toString());
        }
        if (data.get("AVGVResult") != null) {
            entity.setCnsjzc(data.get("AVGVResult").toString());
        }
        if (data.get("AVGVResult") != null) {
            entity.setZnsjzc(data.get("AVGVResult").toString());
        }
        List<ConcreteAdmixtureNjsjzc.NjsjzcList> njsjzcLists = new ArrayList<>();
        ConcreteAdmixtureNjsjzc.NjsjzcList njsjzcListOne = new ConcreteAdmixtureNjsjzc.NjsjzcList();
        if (data.get("S1M1") != null) {
            njsjzcListOne.setSjhntddcnsj(data.get("S1M1").toString());
        }
        if (data.get("S2M1") != null) {
            njsjzcListOne.setJzhntddcnsj(data.get("S2M1").toString());
        }
        if (data.get("S1M1Time") != null) {
            njsjzcListOne.setSjhntjssj(data.get("S1M1Time").toString());
        }
        if (data.get("V1M1") != null) {
            njsjzcListOne.setSjhntddznsj(data.get("V1M1").toString());
        }
        if (data.get("V2M1") != null) {
            njsjzcListOne.setJzhntddznsj(data.get("V2M1").toString());
        }
        njsjzcLists.add(njsjzcListOne);

        ConcreteAdmixtureNjsjzc.NjsjzcList njsjzcListTwo = new ConcreteAdmixtureNjsjzc.NjsjzcList();
        if (data.get("S1M2") != null) {
            njsjzcListTwo.setSjhntddcnsj(data.get("S1M2").toString());
        }
        if (data.get("S2M2") != null) {
            njsjzcListTwo.setJzhntddcnsj(data.get("S2M2").toString());
        }
        if (data.get("S1M2Time") != null) {
            njsjzcListTwo.setSjhntjssj(data.get("S1M2Time").toString());
        }
        if (data.get("V1M2") != null) {
            njsjzcListTwo.setSjhntddznsj(data.get("V1M2").toString());
        }
        if (data.get("V2M2") != null) {
            njsjzcListTwo.setJzhntddznsj(data.get("V2M2").toString());
        }
        njsjzcLists.add(njsjzcListTwo);

        ConcreteAdmixtureNjsjzc.NjsjzcList njsjzcListThree = new ConcreteAdmixtureNjsjzc.NjsjzcList();
        if (data.get("S1M3") != null) {
            njsjzcListThree.setSjhntddcnsj(data.get("S1M3").toString());
        }
        if (data.get("S2M3") != null) {
            njsjzcListThree.setJzhntddcnsj(data.get("S2M3").toString());
        }
        if (data.get("s1M3Time") != null) {
            njsjzcListThree.setSjhntjssj(data.get("s1M3Time").toString());
        }
        if (data.get("V1M3") != null) {
            njsjzcListThree.setSjhntddznsj(data.get("V1M3").toString());
        }
        if (data.get("V2M3") != null) {
            njsjzcListThree.setJzhntddznsj(data.get("V2M3").toString());
        }
        njsjzcLists.add(njsjzcListThree);
        entity.setNjsjzcList(njsjzcLists);
    }
}
